package database.team.generator;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class EmployeeTableGenerator {
        
        public static void main(String[] args)
        {
                Scanner scanner = new Scanner(System.in);
                
                try{
                        System.out.println("enter the no. of records you want to generate for the first employee file");
                        int numberOfRecords1 = scanner.nextInt();
                        System.out.println("generating the first employee file...");
                        generateFileWith(numberOfRecords1, "Emp1");
                        System.out.println("generated the file with "+numberOfRecords1+" records");
                        System.out.println();
                        
                        System.out.println("enter the no. of records you want to generate for the second employee file");
                        int numberOfRecords2 = scanner.nextInt();
                        System.out.println("generating the first employee file...");
                        generateFileWith(numberOfRecords2, "Emp2");
                        System.out.println("generated the file with "+numberOfRecords2+" records");
                        
                }
                catch(IOException e){
                    e.printStackTrace(); 
                }
                finally{
                scanner.close();
                }
                
                
        }
        
        public static void generateFileWith(int numberOfRecords, String filename) throws IOException
        {
                         BufferedWriter fbw;
                         try{
                                 fbw = new BufferedWriter(new FileWriter(filename+".txt"));
                         
                         List<String> records=new ArrayList<String>();
                         int id=1000000;
                         for(int i = 0; i < numberOfRecords; i++)
                         {
                                 
                             String name=null ;
                             int sin=0;
                             String address=null;
                             char alphabets[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','w','x','y','z'};
                             
                             name = generateString(alphabets,10);
                             
                             sin=(int)(Math.random()*100000000);
                             //to assure length of sin is 9
                             if(sin<100000000)
                             {
                                     sin = sin + 100000000;
                             }

                             address=generateString(alphabets,74);
                             String record=(id+name+sin+address);
                             records.add(record);
                             id++;
                         }
                         Collections.shuffle(records);
                         for(String writeRecord: records)
                         {
                                 
                         fbw.write("" + writeRecord);
                         fbw.newLine();
                         }
                         fbw.close();
                         }
                         catch(NullPointerException e)
                         {
                                 e.printStackTrace();
                         }
        
        }
        
        
        public static String generateString(char alphabets[],int length)
        {
                
                String value="";
                for (int i=0;i<(length-1);i++)
                {
                        int randomNumber=(int)(Math.random()*25);
                        value=value+alphabets[randomNumber];
                }
                return value;
        }
        
}
